﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CrmDocman.DataCore;

/// <summary>
/// Summary description for TrangTinhHelper
/// </summary>
public class TrangTinhHelper : TWSData
{
    public TrangTinhHelper()
    {
        m_dao = DataBridge.GetInstance();
    }

    public TrangTinhDataSet LoadTrangTinh()
    {

        TrangTinhDataSet lspDs = new TrangTinhDataSet();
        string sql = m_dao.BuildSelectQuery(lspDs.TrangTinh);

        m_dao.FillDataTable(lspDs.TrangTinh, sql);
        m_dao.Connection.CloseConnection();
        return lspDs;
    }

    public TrangTinhDataSet LoadTrangTinh(int TrangTinhID)
    {

        TrangTinhDataSet lspDs = new TrangTinhDataSet();
        string sql = m_dao.BuildSelectQuery(lspDs.TrangTinh);
        sql += " where ID = " + TrangTinhID;

        m_dao.FillDataTable(lspDs.TrangTinh, sql);
        m_dao.Connection.CloseConnection();
        return lspDs;
    }

    public TrangTinhDataSet LoadTrangTinhViTri(string ViTri, int lang)
    {

        TrangTinhDataSet lspDs = new TrangTinhDataSet();
        string sql = m_dao.BuildSelectQuery(lspDs.TrangTinh);
        sql += " where ViTri = '" + ViTri + "' and Lang = " + lang;

        m_dao.FillDataTable(lspDs.TrangTinh, sql);
        m_dao.Connection.CloseConnection();
        return lspDs;
    }

    public bool SaveTrangTinh(TrangTinhDataSet lspDs)
    {
        m_dao.UpdateDataTable(lspDs.TrangTinh);
        m_dao.Connection.CloseConnection();
        return true;

    }

    public static string GetImageLogo(string ViTri)
    {
        TrangTinhDataSet lspDs = new TrangTinhHelper().LoadTrangTinhViTri(ViTri, 1);
        if (lspDs.TrangTinh.Rows.Count > 0)
        {
            return lspDs.TrangTinh[0].IsNoiDungNull() ? "logo.jpg" : lspDs.TrangTinh[0].NoiDung;
        }
        return "logo.jpg";
    }

}
